- 
                Notifications
    You must be signed in to change notification settings 
- Fork 115
feat: Auto-submitting chat suggestions #1847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
                
     Merged
            
            
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    * Disable input on send * Disable input when appending a message (i.e. while streaming) * Reflect `disabled` state to HTML element (lit's `reflect: true` doesn't work with `LightElement`) * Reflect HTML element changes of `disabled` state back to component
`this.#sendInput()` doesn't send when `this.disabled`, but we still want to emit the input event, etc.
              
                    gadenbuie
  
              
              commented
              
                  
                    Feb 11, 2025 
                  
              
              
            
            
              
                    gadenbuie
  
              
              commented
              
                  
                    Feb 11, 2025 
                  
              
              
            
            
      
        
      
      
  
    2 tasks
  
      
        
      
      
  
    2 tasks
  
              
                    cpsievert
  
              
              reviewed
              
                  
                    Feb 13, 2025 
                  
              
              
            
            
              
                    cpsievert
  
              
              reviewed
              
                  
                    Feb 13, 2025 
                  
              
              
            
            
              
                    cpsievert
  
              
              approved these changes
              
                  
                    Feb 13, 2025 
                  
              
              
            
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This PR stacks on #1845 (and should be merged into it before merging to main).
The goal is to add an option to auto-submit the inline chat suggestion. This required a small amount of refactoring how the disabled input state is handled first, and then giving
ChatInput.setInputValue()asubmitparameter that defaults tofalse.For styling, I've used the idea from @cpsievert in #1845 (comment) to use ↵ for suggestions that will auto-submit and ✦ for suggestions that fill out the input value without submitting. In the screenshot below, the first and third suggestions would auto-submit and the second would just fill out the input.
(I modified the example app below for the screenshot, it's more likely that you'd pick one style or the other for your app.)
The easiest way to create an auto-submitting suggestion is to use
<span class="suggestion submit">, butdata-suggestion-submitanddata-suggestion-submit="true"also work as well.Example app
Along the way, I made a fun little app that works well for me locally with ollama and Phi4.
Example App
Screen.Recording.2025-02-11.at.3.01.18.PM.mov
Notice that clicking the suggestions doesn't usually work while streaming, but it does work if you scroll up to a previous message. That's because, while streaming, the chat message is being re-rendered fast enough that the clicked element no longer exists by the time the click handler runs. I think it's okay for us not to do anything about it, but it's also important that we're not submitting during streaming.